package fakedata

import (
	"doctor_api_backend/config"
	"doctor_api_backend/models"
	"math/rand"
	"time"

	"github.com/bxcodec/faker/v3"
)

// 这个得有其他系统预先准备就诊队列，

// 生成病人就诊等待队列假数据,
// 病人就诊等待队列的唯一标识字段是patient_queue_code

func SeedPatientQueue() {

	// 其中PatientId和DoctorId是来源于已有的病人表和医生表
	patientList := []models.Patient{}
	doctorList := []models.Doctor{}

	config.DB.Find(&patientList)
	config.DB.Find(&doctorList)

	// 生成100条病人就诊等待队列假数据
	for i := 0; i < 100; i++ {
		patientQueue := models.PatientQueue{
			PatientQueueCode:    faker.UUIDDigit(),
			PatientID:           int(patientList[rand.Intn(len(patientList))].PatientId),
			DoctorID:            int(doctorList[rand.Intn(len(doctorList))].DoctorID),
			Name:                faker.Name(),
			MedicalRecordNumber: faker.UUIDDigit(),
			// 10位数
			Gender:     faker.UUIDDigit()[:10],
			Age:        rand.Intn(100),
			Occupation: faker.Word(),
			// 18位身份证号
			IDNumber:       faker.UUIDDigit()[:18],
			FirstVisitTime: generateDate(),
		}
		config.DB.Create(&patientQueue)
	}

}

func generateDate() time.Time {
	year := rand.Intn(10) + 2010
	month := rand.Intn(12) + 1
	day := rand.Intn(28) + 1
	return time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.Local)
}
